﻿using System;
using System.Collections;
using System.ComponentModel;

namespace UIT.ScrumTool.Client.Utilities.UserGridView
{
    public class UserGV : IDataErrorInfo
    {
        protected string companyPosition = string.Empty;
        protected string email = string.Empty;
        protected string firstName = string.Empty;
        protected string id = string.Empty;
        protected string im = string.Empty;
        protected string imType = string.Empty;
        protected string lastName = string.Empty;
        protected string loginName = string.Empty;
        internal IList m_containingList;
        protected string password = string.Empty;
        protected string profile = string.Empty;

        public UserGV()
        {
        }

        public UserGV(string id, string loginName, string pass, string lastName, string firstName, string email,
                      string imType, string im, string position, string pfile)
        {
            this.id = id;
            this.loginName = loginName;
            password = pass;
            this.lastName = lastName;
            this.firstName = firstName;
            this.email = email;
            this.imType = imType;
            this.im = im;
            companyPosition = position;
            profile = pfile;
        }

        public string ID
        {
            set
            {
                id = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
            get { return id; }
        }

        public string Password
        {
            get { return password; }
            set
            {
                password = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public string LastName
        {
            get { return lastName; }
            set
            {
                lastName = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public string FirstName
        {
            get { return firstName; }
            set
            {
                firstName = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public string Email
        {
            get { return email; }
            set
            {
                email = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public string IMType
        {
            get { return imType; }
            set
            {
                imType = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public string IM
        {
            get { return im; }
            set
            {
                im = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public string CompanyPosition
        {
            get { return companyPosition; }
            set
            {
                companyPosition = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public string Profile
        {
            get { return profile; }
            set
            {
                profile = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
        }

        public string LoginName
        {
            set
            {
                loginName = value;
                if (m_containingList != null)
                    InvokeListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged,
                                                               m_containingList.IndexOf(this)));
            }
            get { return loginName; }
        }

        #region IDataErrorInfo Members

        public string Error
        {
            get { return string.Empty; }
        }

        public string this[string columnName]
        {
            get
            {
                string error = string.Empty;

                switch (columnName)
                {
                    case "LoginName":
                        {
                            if (String.IsNullOrEmpty(loginName))
                                error = "The composer's first name should be specified if possible.";
                            break;
                        }
                }

                return error;
            }
        }

        #endregion

        protected virtual void InvokeListChanged(ListChangedEventArgs e)
        {
            ((UserBindingListComplete) m_containingList).InvokeOnListChanged(e);
        }
    }
}